using System;
namespace Microsoft.Expression.Drawing.Core
{
	internal static class MathHelper
	{
		public const double Epsilon = 1E-06;
		public const double TwoPI = 6.2831853071795862;
		public const double PentagramInnerRadius = 0.47211;
		public static bool IsVerySmall(double value)
		{
			return Math.Abs(value) < 1E-06;
		}
		public static bool AreClose(double value1, double value2)
		{
			return value1 == value2 || MathHelper.IsVerySmall(value1 - value2);
		}
		public static bool GreaterThan(double value1, double value2)
		{
			return value1 > value2 && !MathHelper.AreClose(value1, value2);
		}
		public static bool GreaterThanOrClose(double value1, double value2)
		{
			return value1 > value2 || MathHelper.AreClose(value1, value2);
		}
		public static bool LessThan(double value1, double value2)
		{
			return value1 < value2 && !MathHelper.AreClose(value1, value2);
		}
		public static bool LessThanOrClose(double value1, double value2)
		{
			return value1 < value2 || MathHelper.AreClose(value1, value2);
		}
		public static double SafeDivide(double lhs, double rhs, double fallback)
		{
			if (!MathHelper.IsVerySmall(rhs))
			{
				return lhs / rhs;
			}
			return fallback;
		}
		public static double Lerp(double x, double y, double alpha)
		{
			return x * (1.0 - alpha) + y * alpha;
		}
		public static double EnsureRange(double value, double? min, double? max)
		{
			if (min.get_HasValue() && value < min.get_Value())
			{
				return min.get_Value();
			}
			if (max.get_HasValue() && value > max.get_Value())
			{
				return max.get_Value();
			}
			return value;
		}
		public static double Hypotenuse(double x, double y)
		{
			return Math.Sqrt(x * x + y * y);
		}
		public static double DoubleFromMantissaAndExponent(double x, int exp)
		{
			return x * Math.Pow(2.0, (double)exp);
		}
		public static bool IsFiniteDouble(double x)
		{
			return !double.IsInfinity(x) && !double.IsNaN(x);
		}
	}
}
